function splitName(fullName)
    return string.match(fullName, "(%a+) (%a+)")
end

local firstName, lastName = splitName("Lua Script")
print(firstName, lastName)

local square = function(x)
    return x * x
end
print(square(3))

local sum = 0
for i = 0, 10, 1 do
    sum = sum + i
end
print(sum)

local t = {1, 2, nil, 4}
for i = 1, #t do
    if t[i] then
        print(t[i])
    end
end

for _, v in ipairs(t) do
    print(v) -- 输出：1, 2, 4（顺序可能不固定）
end

function safeAverage(...)
    local count = select("#", ...) -- 获取参数总数（包括 nil）
    local sum = 0
    for i = 1, count do
        local v = select(i, ...) -- 获取第 i 个参数（可能为 nil）
        sum = sum + (v or 0) -- 处理 nil 值
    end
    return sum / count
end
print(safeAverage(10, nil, 30)) -- 输出：(10+0+30)/3 = 13.33 [6,7](@ref)

function formatPrint(fmt, ...)
    print(string.format(fmt, ...))
end
formatPrint("%s: %d", "Score", 99)

local tt = {1, 2, nil, 4}
print(tt)
print(table.unpack(tt))

function newCounter()
    local count = 0
    return function()
        count = count + 1
        return count
    end
end

local c1 = newCounter()
local c2 = newCounter()

print(c1())
print(c1())
print(c2())

function onEvent(callback)
    local data = getData()
    return function()
        callback(data)
    end
end

function multiplier(factor)
    return function(x)
        return x * factor
    end
end
local double = multiplier(2)
print(double(10))